package com.example.shijianfenfa;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class MyView extends View {
    String TAG = "MyView";
    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
    /**
     * 处理事件的方法
     * @param event
     * @return
     */
    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        Log.i(TAG, "dispatchTouchEvent: "+event.getAction());
        //super.dispatchTouchEvent(event) 事件分发
        //true:事件消费
        //fasle:事件给到父容器 的onTouchEvent()

        return super.dispatchTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i(TAG, "onTouchEvent: "+event.getAction());
        //true:消费
        //false:和super一样,事件给到父容器的onTouchEvent
        return true;
    }
}
